package com.hotelsystem.util;

import sun.misc.BASE64Decoder;

import java.io.FileOutputStream;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.UUID;

public class Tool {
	public static String createUUID(){
		return UUID.randomUUID().toString().replace("-", "");
	}

	/**
	 * 将图片的Base64字符串，反转为字节数组，最后写入指定图片文件中
	 * @param imgBase64
	 * @param filePath
	 * @throws Exception
	 */
	public static void writeImgBase64ToFile(String imgBase64,String filePath)throws Exception{
		if(imgBase64 == null || imgBase64.length() == 0) return;
		
		//判断是否带有协议前缀：
		if(imgBase64.startsWith("data")){
			imgBase64 = imgBase64.substring(imgBase64.indexOf(",") + 1);
		}
		BASE64Decoder decoder = new BASE64Decoder();
		byte[] bs = decoder.decodeBuffer(imgBase64);
		FileOutputStream fos = new FileOutputStream(filePath);
		fos.write(bs);
		fos.close();

	}

	public static String DataConvertStr(Date date){
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
		return sdf.format(date);
	}



}
